package cn.com.infohold.smartcity.utils;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangyahui on 2017/1/18.
 */

public class StringUtils {
    public static String fixedKey(String key) {
        if (TextUtils.isEmpty(key)) {
            return key;
        }
        int length = key.length();
        StringBuilder sb = new StringBuilder();
        String space;
        switch (length) {
            case 2:
                space = "\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020";
                break;
            case 3:
                space = "\u0020\u0020";
                break;
            default:
                space = "";
                break;
        }
        for (int i = 0; i < length; i++) {
            sb.append(key.charAt(i));
            if (i < length - 1) {
                sb.append(space);
            }
        }
        return sb.toString();
    }
    public static boolean isNotBlank(String str) {
        return str != null && !"".equals(str);
    }

    public static boolean isBlank(String str) {
        return str == null || "".equals(str);
    }

    public static String join(List<String> list, String seperator) {
        if (list.isEmpty()) {
            return "";
        }
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i)).append(seperator);
        }
        return sb.substring(0, sb.length() - seperator.length());
    }
    public static List<String> asList(String str, String seperator) {
        if (isBlank(str)) {
            return new ArrayList<String>();
        }
        String [] strs=str.split(seperator);
        List<String> list=new ArrayList<String>();
        for(String string:strs){
            list.add(string);
        }
        return list;
    }

}
